/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package shared;

import java.awt.Graphics2D;
import java.awt.Point;
import java.io.IOException;
//import java.io.Serializable;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;

/**
 *
 * @author konp
 */
public class Bullet extends MovingObject// implements Serializable 
{

    public Player owner;
    public long startTimer;
    public Point.Double velocity;
    private SerializableBufferedImage img;
    Point.Double pos2 = new Point.Double();

    
    public Bullet(Player _owner, Point.Double start_pos, Point.Double start_vel) {
        radius = 5;
        velocity = start_vel;
        pos = new Point.Double(start_pos.x, start_pos.y);
        pos2 = pos;
        owner = _owner;
        
        switch (owner.number) {
            case 0:
                try {
                    img = new SerializableBufferedImage(ImageIO.read(this.getClass().getResourceAsStream("resources/player1.png")));
                } catch (IOException ex) {
                    Logger.getLogger(Map.class.getName()).log(Level.SEVERE, null, ex);
                }
                break;

            case 1:
                try {
                    img = new SerializableBufferedImage(ImageIO.read(this.getClass().getResourceAsStream("resources/player3.png")));
                } catch (IOException ex) {
                    Logger.getLogger(Map.class.getName()).log(Level.SEVERE, null, ex);
                }
                break;

            case 2:
                try {
                    img = new SerializableBufferedImage(ImageIO.read(this.getClass().getResourceAsStream("resources/player2.png")));
                } catch (IOException ex) {
                    Logger.getLogger(Map.class.getName()).log(Level.SEVERE, null, ex);
                }
                break;

            default:
                try {
                    img = new SerializableBufferedImage(ImageIO.read(this.getClass().getResourceAsStream("resources/player2.png")));
                } catch (IOException ex) {
                    Logger.getLogger(Map.class.getName()).log(Level.SEVERE, null, ex);
                }
                break;
        }
        
        startTimer = new Date().getTime();
    }

    public void draw(Graphics2D g2d) {
        g2d.drawImage(img.getBufferedImage(), (int)pos2.x, (int)pos2.y, 10, 10, null);
    }

    public void moveBy(double x, double y) {
        pos.x += x;
        pos.y += y;
        pos2.x = pos.x;
        pos2.y = pos.y;
    }
}
